package b3.widget.home.user
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.scene.home.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	
	public class PopulationPane extends Sprite
	{
		private var populationBar:MaskProgressBar;
		private var populationText:TextField;
		private var levelText:TextField;
		private var titleText:TextField;
		
		public function PopulationPane()
		{
			super();
			var PopulationBar:Class = ResourceHelper.getInstance().getClassByName("PopulationBar");
			populationBar = new MaskProgressBar(PopulationBar);
			addChild(populationBar);
			populationText = new TextField();
			populationText.selectable = false;
        	populationText.autoSize = TextFieldAutoSize.CENTER;
			populationText.defaultTextFormat = new TextFormat(BFont.fontName, 10, 0x000000);
			populationText.x = 35;
			populationText.y = -6;
			addChild(populationText);
			levelText = new TextField();
			levelText.selectable = false;
        	levelText.autoSize = TextFieldAutoSize.CENTER;
			levelText.defaultTextFormat = new TextFormat(BFont.fontName, 11, 0x005500);
			levelText.x = 5;
			levelText.y = 10;
			addChild(levelText);
			titleText = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
			titleText.defaultTextFormat = new TextFormat(BFont.fontName, 11, 0x005500);
			titleText.x = 38;
			titleText.y = 10;
			addChild(titleText);
			PlayerManager.getInstance().me.packageModel.addEventListener(ModelEvent.REFRESH, onRefresh);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			this.mouseChildren = false;
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			var container:Sprite = new Sprite();		
			//图标
			var GoldCoinIcon:Class = ResourceHelper.getInstance().getClassByName("PopulationIcon");
			var goldCoinIcon:Sprite = new GoldCoinIcon();
			goldCoinIcon.height = 60;
			goldCoinIcon.scaleX = goldCoinIcon.scaleY;
			goldCoinIcon.x = 10;
			goldCoinIcon.y = 0;
			container.addChild(goldCoinIcon);
			//金币
			var me:Player = PlayerManager.getInstance().me;
			var goldCoinText:TextField = new TextField();
			goldCoinText.selectable = false;
			goldCoinText.autoSize = TextFieldAutoSize.LEFT;
			goldCoinText.defaultTextFormat = new TextFormat("微软雅黑", 25, 0xFFFFFF, true);
			goldCoinText.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			goldCoinText.text = "城市总人口";
			goldCoinText.x = 65;
			goldCoinText.y = 12;
			container.addChild(goldCoinText);
			HomeScene.getInstance().centerInfoPane.showInfo(container);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}

		private function onRefresh(event:Event):void
		{
			var me:Player = PlayerManager.getInstance().me;
			var population:int = me.packageModel.getObjectNum(ObjConfig.POPULATION);
			var level:int = Config.getLevel(ObjConfig.POPULATION, population);
			var currentHonourConfig:HonourConfig = Config.honourArrays[ObjConfig.POPULATION][level];
			var nextHonourConfig:HonourConfig = Config.honourArrays[ObjConfig.POPULATION][level + 1];
			populationBar.percentage = population / nextHonourConfig.require;
			populationText.text = population + "/" + nextHonourConfig.require;
			levelText.htmlText = "<i>" + level + ". </i>";
			titleText.text = currentHonourConfig.title;
		}

	}
}